home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / DIRS.SWG / 0001_DOS Directories.pas next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  2.1 KB  |  62 lines

  1. {
  2.  Below you'll find a program that lists all the directories on the C drive. It
  3.  can be extended very easily but it just wanted to show the basics. (It was
  4.  part of a program that did for dos what the DELTREE command does now. I used
  5.  to work (good old days) with Dos 3.3 which doesn't have a DELTREE command)
  6.  
  7.  {-------------------------------------------------------------------------}
  8.  { programmer : David van Driessche  (2:291/1933.13)                       }
  9.  { language   : Borland Pascal v7.0                                        }
  10.  { purpose    : explaining recursive directory listings                    }
  11.  {-------------------------------------------------------------------------}
  12.  
  13.  {- This code is public domain, feel free to do with it any descent thing -}
  14.  
  15.  program GetDirInfo ;
  16.  
  17.  uses Dos, Crt ;
  18.  
  19.  var
  20.   DirCounter : Integer ;
  21.   Scherm     : Text ;
  22.  
  23.  procedure Show( Direct : String ) ;
  24.   var
  25.    {
  26.     Info must be a local parameter of Show. This way the information in the
  27.     SearchRec is saved when a subdirectory is explored using recursion.
  28.    }
  29.    Info : SearchRec ;
  30.   begin
  31.    { We have to search the directory in Direct, build the search-path }
  32.    if ( Direct[Length(Direct)] <> '\' ) THEN Direct := Direct + '\' ;
  33.    FindFirst( Direct+'*.*', AnyFile, Info ) ;
  34.    { As long as we have 'things' in the Direct directory, look at them }
  35.    while ( DosError = 0 ) do
  36.     begin
  37.      if ( (Info.Name <> '.') and (Info.Name <> '..') and
  38.           ( (Info.Attr and Directory) = Directory) )
  39.       then
  40.        begin
  41.         { We found one directory more }
  42.         Inc ( DirCounter ) ;
  43.         { Show what we found }
  44.         Writeln( Direct+Info.Name ) ;
  45.         { We will now search that directory }
  46.         Show( Direct+Info.Name ) ;
  47.        end ;
  48.      { Are there any more things out there ? If so, look at them }
  49.      FindNext( Info ) ;
  50.     end ;
  51.   end ;
  52.  
  53.  begin
  54.   AssignCrt( Scherm ) ;
  55.   ReWrite( Scherm ) ;
  56.   DirCounter := 0 ;
  57.   Show ( 'C:\' ) ;
  58.   Writeln( Scherm ) ;
  59.   Writeln( Scherm, 'Number of directories = ', DirCounter:0 ) ;
  60.  end.
  61.  
  62.